package com.googlecode.afdbaccess.web.common.exception;

import javax.servlet.http.HttpServletResponse;

public class GuiLayerException extends Exception {
    public static class Severity {
        public final static Severity ERROR = new Severity("ERROR");
        public final static Severity INFO = new Severity("INFO");
        
        private String severity;
        
        public Severity(String severity) {
            this.severity = severity;
        }
        
        public String getSeverity() {
            return this.severity;
        }
        
        @Override
        public String toString() {
            return "Severity[\"" + severity + "\"]";
        }
    }
    
    private String longMessage = null;
    private boolean showStackTrace = false;
    
    private Severity severity = Severity.ERROR;
    private int httpReturnCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    
    public GuiLayerException(String message, Throwable cause) {
        super(message, cause);
    }
    
    public GuiLayerException(String message, boolean showStackTrace, Throwable cause) {
        super(message, cause);
        this.showStackTrace = showStackTrace;
    }

    public GuiLayerException(String message, String longMessage, Throwable cause) {
        super(message, cause);
        this.longMessage = longMessage;
    }
    
    public GuiLayerException(String message, String longMessage, boolean showStackTrace, Throwable cause) {
        super(message, cause);
        this.longMessage = longMessage;
        this.showStackTrace = showStackTrace;
    }

    public GuiLayerException(String message) {
        super(message);
    }
    
    public GuiLayerException(String message, boolean showStackTrace) {
        super(message);
        this.showStackTrace = showStackTrace;
    }
    
    public GuiLayerException(String message, String longMessage) {
        super(message);
        this.longMessage = longMessage;
    }
    
    public GuiLayerException(String message, String longMessage, boolean showStackTrace) {
        super(message);
        this.longMessage = longMessage;
        this.showStackTrace = showStackTrace;
    }
    
    public String getLongMessage() {
        return this.longMessage;
    }

    public boolean getShowStackTrace() {
        return showStackTrace;
    }
    
    //
    
    /**
     * This sets the "GUI" severity, that is, how the message should be presented (that is, red text, blue text, warning sign, etc).
     * For the "logging" severity, see the showStackTrace variable instead.
     */
    public void setSeverity(Severity severity) {
        this.severity = severity;
    }
    
    public Severity getSeverity() {
        return this.severity;
    }
    
    //
    
    public void setHttpReturnCode(int httpReturnCode) {
        this.httpReturnCode = httpReturnCode;
    }
    
    public int getHttpReturnCode() {
        return this.httpReturnCode;
    }
    
    //
    
    @Override
    public String toString() {
        return super.toString() + "\n" +
          "Severity: " + getSeverity() + ", Http return code: " + getHttpReturnCode() +
          ((longMessage != null)?"\nLongMessage:\n" + longMessage : "");
    }
}